Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support glob patterns #151

Merged
merged 4 commits into from
Sep 22, 2021
Merged

Conversation

achingbrain
Copy link
Member

@achingbrain achingbrain commented Sep 15, 2021

We use a weird mix of multiple glob patterns and ignores which means we parse the available files in an inefficient way.

Instead just use a single glob pattern which can do everything we need.

Fixes ipfs/js-ipfs#2885

BREAKING CHANGE: the globSource call signature has changed and no longer supports the recursive or ignore options

We use a weird mix of multiple glob patterns and ignores which means
we parse the available files in an inefficient way.

Instead just use a single glob pattern which can do everything we
need.

Fixes ipfs/js-ipfs#2885
const absolutePath = Path.resolve(process.cwd(), path)
const stat = await fsp.stat(absolutePath)
const prefix = Path.dirname(absolutePath)
const globOptions = Object.assign({}, pattern, {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pattern is a string no? Why assigning options to it?

Copy link
Member Author

@achingbrain achingbrain Sep 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent point.

)
}
if (pattern.startsWith('.' + Path.sep)) {
pattern = pattern.replace('.' + Path.sep, '')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this bit guard against?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With hindsight I don't think it's necessary, I've removed it.

* @param {boolean} [options.followSymlinks] - follow symlinks
* @param {boolean} [options.preserveMode] - preserve mode
* @param {boolean} [options.preserveMtime] - preserve mtime
* @param {number} [options.mode] - mode to use - if preserveMode is true this will be ignored
* @param {import('ipfs-unixfs').MtimeLike} [options.mtime] - mtime to use - if preserveMtime is true this will be ignored
* @yields {Object} File objects in the form `{ path: String, content: AsyncIterator<Buffer> }`
*/
module.exports = async function * globSource (paths, options) {
module.exports = async function * globSource (pattern, options) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be tempted to make this take cwd, pattern, options to avoid some of the cwd messing around bits.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, I'm, always wondering where the output path will start.

@achingbrain achingbrain merged commit d626de1 into master Sep 22, 2021
@achingbrain achingbrain deleted the feat/use-proper-glob-patterns branch September 22, 2021 11:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove recursive/ignore option from ipfs.addFromFs and accept globs?
2 participants